home *** CD-ROM | disk | FTP | other *** search
- /* Path names
- * Copyright 1988 Greg Coleman
- * These sources may be freely distributed provided this notice
- * remains intact.
- */
-
- # define mfsSigWord 0xd2d7;
- # define hfsSigWord 0x4244;
- # define rootDirID 2
- # include <Files.h>
- # include "Tonto.h"
- /*
- * Given a partial path name and a volume (or working directory)
- * reference number, construct an absolute path up to, but not
- * including, the partial path.
- * The input partial path string is replaced.
- * The third parameter is the length of the string buffer.
- */
- StringPtr
- pathname(pname, vRefNum, n)
- StringPtr pname;
- Integer vRefNum;
- int n;
- {
- OSErr result;
- int m; /* length so far */
- CInfoPBRec ci;
- Str255 dname; /* path component name */
- Str255 tname; /* temp space */
- #define dp ci.dirInfo
-
- if (n > sizeof(tname))
- n = sizeof(tname);
- m = pname[0];
- if (m == 0) {
- return;
- }
- /*
- * Find the folder containing the supplied file/folder
- */
- ZERO(ci);
- ci.hFileInfo.ioNamePtr = pname;
- ci.hFileInfo.ioVRefNum = vRefNum;
- result = PBGetCatInfo(&ci, FALSE);
-
- pname[0] = m = 0;
- dp.ioNamePtr = dname;
-
- if (result == noErr)
- {
- do
- {
- dp.ioDrDirID = dp.ioDrParID;
- dp.ioDrParID = 0;
- dp.ioFDirIndex = -1;
- dname[0] = '\0';
- if (result = PBGetCatInfo(&ci,0))
- break;
-
- if (m + dname[0] >= n) {
- pname[0] = 0;
- break;
- }
- pstrcat2 (tname, (SP)"\p:", pname);
- pstrcat2 (pname, dname, tname);
- m = pname[0];
- } while (dp.ioDrDirID != rootDirID);
- if (pname[m] == ':')
- pname[0] = --m;
- }
- return pname;
- }